<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="${pageContext.request.contextPath }/intranet/js/text.readonly.true.js"></script>
<title>Insert title here</title>
<style type="text/css">
	.cont_sal_info, .cont_cont_info{
		border: 3px solid gray;
	}
	.cont_sal_info div, .cont_cont_info div{
		vertical-align: middle;
	}
	.cont_sal_info div div, .cont_cont_info div div{
		display: inline-block;
		margin: 0;
		width: 49%;
		padding: 5px;
	}
	.cont_sal_info div div:FIRST-CHILD, .cont_cont_info div div:FIRST-CHILD{
		border-right: 1px solid gray;
	}
	.cont_sal_info div div p, .cont_cont_info div div p{
		display: inline-block;
		margin: 0;
		padding: 0;
		height: 30px;
		width: 65%;
		vertical-align: middle;
	}
	.cont_sal_info div div p:FIRST-CHILD, .cont_cont_info div div p:FIRST-CHILD{
		background-color: #eeeeee;
		border: 1px solid gray;
		width: 30%;
		vertical-align: middle;
	}
	input[type=text]{
		margin: 0;
		height: 30px;
		width: 90%;
		vertical-align: middle;
	}
</style>
<script type="text/javascript">
	window.onload = function(){
		readOnly();
	};
	
	function fnGoList() {
		var list = document.getElementById("list");
		list.submit();
	}
	
	function openViewWindow() {
		var pd_rate = "${dto.pd_rate}";
		var pd_prd = "${dto.pd_prd}";
		pd_rate = pd_rate.replace("%", "");//%때문에 파라미터가 안넘어가서 %잘라냄
		pd_prd = pd_prd.replace("개월", "");
		var url = "../intranet/approval/ap_popup.jsp?ct_no=${dto.ct_no}&sa_no=${dto.sa_no}&sa_no_nm=${dto.sa_nm}";
		url += "&ct_ing=${dto.ct_ing}&ct_ing_nm=${cting}&pd_prd="+pd_prd+"&rg_pp=${dto.rg_pp}&rg_pp_nm=${dto.rg_pp_nm}";
		url += "&cs_loan=${dto.cs_loan}&pd_rate="+pd_rate+"&pd_pback=${dto.pd_pback}&ap_no=${dto.ap_no}&cs_max=${dto.cs_max}";
		if(window._childwin){
			alert("이미 결재 팝업창이 열려있습니다.");
		}else{
			window._childwin = window.open(url, "_blank", "resizable=yes, top=100, left=200, width=670, height=650");
		}
	}
	function fnUpdate() {
		if("${sessionScope.mid}" != "${dto.rg_pp}"){
			alert("권한이 없습니다!");
		}else{
			//alert("들어옴");
			$.ajax({
				//url : '${pageContext.request.contextPath}/Cont/ContUp.clamp',
				url : '${pageContext.request.contextPath}/intranet/contract/contract_update.jsp',
				type : 'GET',
				cache : false,
				data : 'ct_no=${dto.ct_no}',
				success: function(result){
					$("#ct_ing").val("계약만료 (${dto.ap_no})");
					alert("계약만료 처리되었습니다.");
					var btn = document.getElementById("btnEND");
					btn.style.display = "none";
				},error:function(request,status,error){
				    alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
				}
			});
		}
	}
	
	function fnSchedule() {
		var url = "${pageContext.request.contextPath}/homepage/product/schedule.jsp?CT_NO=${dto.ct_no}";
		if(window._childwin){
			alert("이미 스케쥴 팝업창이 열려있습니다.");
		}else{
			window._childwin = window.open(url, "_blank", "resizable=yes, top=100, left=200, width=670, height=650");
		}
	}
</script>
</head>
<body>
	<div align="center">
		<div style="width: 1200px;">
			<h1>계약 상세보기<small>Contract View</small></h1>
			<div align="right" style="width: 100%; margin-top: 30px;">
				<fmt:parseDate var="loan_end" value="${dto.cs_loan_end }" type="date" pattern="yyyy-MM-dd"/>
				<fmt:formatDate var="end" value="${loan_end}" pattern="yyyy-MM-dd"/>
				<fmt:formatDate var="today" value="${date }" pattern="yyyy-MM-dd"/>
				<c:if test="${dto.ct_ing eq '03' and end lt today }">
					<input type="button" id="btnEND" value="계약만료" class="btn btn-danger" onclick="fnUpdate()">
				</c:if>
				<c:if test="${dto.ct_ing eq '03' or dto.ct_ing eq '06' }">
					<input type="button" id="btnEND" value="스케쥴" class="btn btn-danger" onclick="fnSchedule()">
				</c:if>
				<c:if test="${dto.ct_ing eq '01' or dto.ct_ing eq '02' }">
					<input type="button" value="결재" class="btn btn-danger" onclick="openViewWindow()">
				</c:if>
				<input type="button" value="목록" class="btn btn-primary" onclick="fnGoList()">
			</div>
			<div style="height: 20px;"></div>
			<div>
				<div>
					<h3>대출자 정보</h3>
					<div class="cont_sal_info">
						<div>
							<div>
								<p>계약자 사번</p>
								<p><input type="text" value="${dto.sa_no }"></p>
							</div>
							<div>
								<p>계약자 이름</p>
								<p><input type="text" value="${dto.sa_nm }"></p>
							</div>
						</div>
						<div>
							<div>
								<p>부서</p>
								<p><input type="text" value="${sadp }"></p>
							</div>		
							<div>
								<p>직급</p>
								<p><input type="text" value="${pst }"></p>
							</div>			
						</div>
						<div>
							<div>
								<p>이메일</p>
								<p><input type="text" value="${dto.sa_email }"></p>
							</div>		
							<div>
								<p>연락처</p>
								<p><input type="text" value="${dto.sa_ph }"></p>
							</div>			
						</div>
						<div>
							<div>
								<p>은행명</p>
								<p><input type="text" value="${dto.sa_bknm }"></p>
							</div>		
							<div>
								<p>계좌번호</p>
								<p><input type="text" value="${dto.sa_acc }"></p>
							</div>			
						</div>
					</div>
				</div>
				<div>
					<h3>계약 정보</h3>
					<div class="cont_cont_info">
						<div>
							<div>
								<p>계약번호</p>
								<p><input type="text" value="${dto.ct_no }"></p>
							</div>
							<div>
								<c:choose>
									<c:when test="${dto.ct_ing != '01' and dto.ct_ing != '02' }">
										<p>계약상태 (결재번호)</p>
										<p><input type="text" id="ct_ing" value="${cting } (${dto.ap_no })" style="background-color: yellow; font-weight: bold;"></p>
									</c:when>
									<c:when test="${dto.ct_ing == '02' }">
										<p>계약상태</p>
										<p><input type="text" value="${cting }" style="background-color: yellow; font-weight: bold;"></p>
									</c:when>
									<c:otherwise>
										<p>계약상태</p>
										<p><input type="text" value="${cting }"></p>
									</c:otherwise>
								</c:choose>
							</div>
						</div>
						<div>
							<div>
								<p>상품번호</p>
								<p><input type="text" value="${dto.pd_no }"></p>
							</div>		
							<div>
								<p>상품명</p>
								<p><input type="text" value="${dto.pd_nm }"></p>
							</div>	
						</div>
						<div>
							<div>
								<p>대출액</p>
								<p><input type="text" value="${dto.cs_loan }만원"></p>
							</div>		
							<div>
								<p>금리</p>
								<p><input type="text" value="${dto.pd_rate }"></p>
							</div>
						</div>
						<div>
							<div>
								<p>상환방법</p>
								<p><input type="text" value="${dto.pd_pback }"></p>
							</div>
							<div>
								<p>대출 기간</p>
								<p><input type="text" value="${dto.pd_prd }"></p>
							</div>
						</div>
						<div>
							<c:if test="${dto.ct_ing eq '03' or dto.ct_ing eq '06'}">
								<div>
									<p>초회 납입일</p>
									<p><input type="text" value="${fn:substring(dto.cs_loan_start,0,10) }" style="background-color: yellow; font-weight: bold;"></p>
								</div>		
								<div>
									<p>대출 만기일</p>
									<p><input type="text" value="${fn:substring(dto.cs_loan_end ,0,10) }" style="background-color: yellow; font-weight: bold;"></p>
								</div>	
							</c:if>
						</div>
						<div>
							<div>
								<p>계약 담당자</p>
								<p><input type="text" value="${dto.rg_pp_nm}(${dto.rg_pp })"></p>
							</div>		
							<div>
								<p>계약 등록일</p>
								<p><input type="text" value="${fn:substring(dto.rg_dt,0,10) }"></p>
							</div>	
						</div>
						<div>
							<c:if test="${dto.ct_ing eq '03' or dto.ct_ing eq '06'}">
								<div>
									<p>계약 승인자</p>
									<p><input type="text" value="${dto.md_pp_nm}(${dto.md_pp })"></p>
								</div>		
								<div>
									<p>계약 처리일</p>
									<p><input type="text" value="${fn:substring(dto.md_dt,0,10) }"></p>
								</div>	
							</c:if>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<form action="${pageContext.request.contextPath}/Cont/ContList.clamp" method="post" id="list" name="list">
		<input type="hidden" name="list" value="list">
	</form>
</body>
</html>